package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.CartDto;
import com.qs.pojo.dto.UserGoodsLogDto;
import com.qs.response.Response;
import com.qs.service.IUserGoodsLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户购买商品历史表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-12-09
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/user/goods/log")
@RequiredArgsConstructor
public class UserGoodsLogController {

    private final IUserGoodsLogService userGoodsLogService;

    /**
     * 获取当前用户的待发货商品
     * @param userId
     * @return
     */
    @GetMapping("/wait/delivery/goods/{userId}")
    public Response getWaitDelivery(@PathVariable("userId") Integer userId){
        log.info("获取当前用户的待发货商品请求进来-----------");
        List<UserGoodsLogDto> cartDtoList = userGoodsLogService.getWaitDelivery(userId);
        return Response.success(cartDtoList);
    }

    /**
     * 获取当前用户的待收货商品
     * @param userId
     * @return
     */
    @GetMapping("/wait/take/goods/{userId}")
    public Response getWaitTake(@PathVariable("userId") Integer userId){
        log.info("获取当前用户的待收货商品请求进来-----------");
        List<UserGoodsLogDto> cartDtoList = userGoodsLogService.getWaitTake(userId);
        return Response.success(cartDtoList);
    }

    /**
     * 获取当前用户的待评价商品
     * @param userId
     * @return
     */
    @GetMapping("/wait/comment/goods/{userId}")
    public Response getWaitComment(@PathVariable("userId") Integer userId){
        log.info("获取当前用户的待评价商品请求进来-----------");
        List<UserGoodsLogDto> cartDtoList = userGoodsLogService.getWaitComment(userId);
        return Response.success(cartDtoList);
    }

    /**
     * 获取当前用户的已完结商品
     * @param userId
     * @return
     */
    @GetMapping("/end/goods/{userId}")
    public Response getEndGoods(@PathVariable("userId") Integer userId){
        log.info("获取当前用户的已完结商品请求进来-----------");
        List<UserGoodsLogDto> cartDtoList = userGoodsLogService.getEndGoods(userId);
        return Response.success(cartDtoList);
    }

    /**
     * 确认收货接口
     * @param goodsId
     * @return
     */
    @PostMapping("/confirm/take/{goodsId}/{orderId}")
    public Response confirmTakeGoods(@PathVariable("goodsId") Integer goodsId,
                                     @PathVariable("orderId") String orderId){
        log.info("确认收货接口请求进来-----------");
        userGoodsLogService.confirmTakeGoods(goodsId,orderId);
        return Response.success();
    }

    /**
     * 获取待发货的订单
     * @param pageNo
     * @param pageSize
     * @param storeId
     * @return
     */
    @GetMapping("/backend/wait/order/{pageNo}/{pageSize}/{storeId}")
    public Response getWaitOrders(@PathVariable("pageNo") Integer pageNo,
                                  @PathVariable("pageSize") Integer pageSize,
                                  @PathVariable("storeId") Integer storeId){
        log.info("获取待发货的商品请求进来-----------");
        Map<String,Object> userDoodsLogMap = userGoodsLogService.getWaitOrders(pageNo,pageSize,storeId);
        return Response.success(userDoodsLogMap);
    }

    /**
     * 获取待收货的商品
     * @param pageNo
     * @param pageSize
     * @param storeId
     * @return
     */
    @GetMapping("/backend/wait/order/take/{pageNo}/{pageSize}/{storeId}")
    public Response getTakeGoods(@PathVariable("pageNo") Integer pageNo,
                                  @PathVariable("pageSize") Integer pageSize,
                                  @PathVariable("storeId") Integer storeId){
        log.info("获取待收货的商品请求进来-----------");
        Map<String,Object> userDoodsLogMap = userGoodsLogService.getTakeGoods(pageNo,pageSize,storeId);
        return Response.success(userDoodsLogMap);
    }

    /**
     * 获取已收货的商品
     * @param pageNo
     * @param pageSize
     * @param storeId
     * @return
     */
    @GetMapping("/backend/wait/order/received/{pageNo}/{pageSize}/{storeId}")
    public Response getReceivedGoods(@PathVariable("pageNo") Integer pageNo,
                                 @PathVariable("pageSize") Integer pageSize,
                                 @PathVariable("storeId") Integer storeId){
        log.info("获取已收货的商品请求进来-----------");
        Map<String,Object> userDoodsLogMap = userGoodsLogService.getReceivedGoods(pageNo,pageSize,storeId);
        return Response.success(userDoodsLogMap);
    }


    /**
     * 后台发货接口
     * @param id
     * @return
     */
    @PostMapping("/backend/wait/order/delivery/{id}")
    @OperationLog(operModul = "商品管理-后台发货",operDesc = "后台发货接口")
    public Response toDoDelivery(@PathVariable("id") Integer id){
        log.info("后台发货接口请求进来-----------");
        userGoodsLogService.toDoDelivery(id);
        return Response.success();
    }
}
